/*
 * Copyright (c) 2024 vitasystems GmbH
 *
 * This file is part of project EHRbase Migration Tool
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.ehrbase.migration.importer.v4.jooq.pg.tables;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;
import org.ehrbase.migration.importer.v4.jooq.pg.Keys;
import org.ehrbase.migration.importer.v4.jooq.pg.tables.records.EhrFolderDataRecord;
import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Function15;
import org.jooq.JSONB;
import org.jooq.Name;
import org.jooq.Record;
import org.jooq.Records;
import org.jooq.Row15;
import org.jooq.Schema;
import org.jooq.SelectField;
import org.jooq.Table;
import org.jooq.TableField;
import org.jooq.TableOptions;
import org.jooq.UniqueKey;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.jooq.impl.TableImpl;

/**
 * This class is generated by jOOQ.
 */
@SuppressWarnings({"all", "unchecked", "rawtypes", "this-escape"})
public class EhrFolderData extends TableImpl<EhrFolderDataRecord> {

    private static final long serialVersionUID = 1L;

    /**
     * The reference instance of <code>ehr.ehr_folder_data</code>
     */
    public static final EhrFolderData EHR_FOLDER_DATA = new EhrFolderData();

    /**
     * The class holding records for this type
     */
    @Override
    public Class<EhrFolderDataRecord> getRecordType() {
        return EhrFolderDataRecord.class;
    }

    /**
     * The column <code>ehr.ehr_folder_data.vo_id</code>.
     */
    public final TableField<EhrFolderDataRecord, UUID> VO_ID =
            createField(DSL.name("vo_id"), SQLDataType.UUID.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_folder_data.num</code>.
     */
    public final TableField<EhrFolderDataRecord, Integer> NUM =
            createField(DSL.name("num"), SQLDataType.INTEGER.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_folder_data.ehr_id</code>.
     */
    public final TableField<EhrFolderDataRecord, UUID> EHR_ID =
            createField(DSL.name("ehr_id"), SQLDataType.UUID.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_folder_data.ehr_folders_idx</code>.
     */
    public final TableField<EhrFolderDataRecord, Integer> EHR_FOLDERS_IDX =
            createField(DSL.name("ehr_folders_idx"), SQLDataType.INTEGER.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_folder_data.citem_num</code>.
     */
    public final TableField<EhrFolderDataRecord, Integer> CITEM_NUM =
            createField(DSL.name("citem_num"), SQLDataType.INTEGER, this, "");

    /**
     * The column <code>ehr.ehr_folder_data.rm_entity</code>.
     */
    public final TableField<EhrFolderDataRecord, String> RM_ENTITY =
            createField(DSL.name("rm_entity"), SQLDataType.CLOB.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_folder_data.entity_concept</code>.
     */
    public final TableField<EhrFolderDataRecord, String> ENTITY_CONCEPT =
            createField(DSL.name("entity_concept"), SQLDataType.CLOB, this, "");

    /**
     * The column <code>ehr.ehr_folder_data.entity_name</code>.
     */
    public final TableField<EhrFolderDataRecord, String> ENTITY_NAME =
            createField(DSL.name("entity_name"), SQLDataType.CLOB, this, "");

    /**
     * The column <code>ehr.ehr_folder_data.entity_attribute</code>.
     */
    public final TableField<EhrFolderDataRecord, String> ENTITY_ATTRIBUTE =
            createField(DSL.name("entity_attribute"), SQLDataType.CLOB, this, "");

    /**
     * The column <code>ehr.ehr_folder_data.entity_path</code>.
     */
    public final TableField<EhrFolderDataRecord, String> ENTITY_PATH =
            createField(DSL.name("entity_path"), SQLDataType.CLOB.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_folder_data.entity_path_cap</code>.
     */
    public final TableField<EhrFolderDataRecord, String> ENTITY_PATH_CAP =
            createField(DSL.name("entity_path_cap"), SQLDataType.CLOB.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_folder_data.entity_idx</code>.
     */
    public final TableField<EhrFolderDataRecord, String> ENTITY_IDX =
            createField(DSL.name("entity_idx"), SQLDataType.CLOB.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_folder_data.entity_idx_cap</code>.
     */
    public final TableField<EhrFolderDataRecord, String> ENTITY_IDX_CAP =
            createField(DSL.name("entity_idx_cap"), SQLDataType.CLOB.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_folder_data.entity_idx_len</code>.
     */
    public final TableField<EhrFolderDataRecord, Integer> ENTITY_IDX_LEN =
            createField(DSL.name("entity_idx_len"), SQLDataType.INTEGER.nullable(false), this, "");

    /**
     * The column <code>ehr.ehr_folder_data.data</code>.
     */
    public final TableField<EhrFolderDataRecord, JSONB> DATA =
            createField(DSL.name("data"), SQLDataType.JSONB.nullable(false), this, "");

    private EhrFolderData(Name alias, Table<EhrFolderDataRecord> aliased) {
        this(alias, aliased, null);
    }

    private EhrFolderData(Name alias, Table<EhrFolderDataRecord> aliased, Field<?>[] parameters) {
        super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table());
    }

    /**
     * Create an aliased <code>ehr.ehr_folder_data</code> table reference
     */
    public EhrFolderData(String alias) {
        this(DSL.name(alias), EHR_FOLDER_DATA);
    }

    /**
     * Create an aliased <code>ehr.ehr_folder_data</code> table reference
     */
    public EhrFolderData(Name alias) {
        this(alias, EHR_FOLDER_DATA);
    }

    /**
     * Create a <code>ehr.ehr_folder_data</code> table reference
     */
    public EhrFolderData() {
        this(DSL.name("ehr_folder_data"), null);
    }

    public <O extends Record> EhrFolderData(Table<O> child, ForeignKey<O, EhrFolderDataRecord> key) {
        super(child, key, EHR_FOLDER_DATA);
    }

    @Override
    public Schema getSchema() {
        return aliased() ? null : org.ehrbase.migration.importer.v4.jooq.pg.Ehr.EHR;
    }

    @Override
    public UniqueKey<EhrFolderDataRecord> getPrimaryKey() {
        return Keys.EHR_FOLDER_PKEY;
    }

    @Override
    public List<ForeignKey<EhrFolderDataRecord, ?>> getReferences() {
        return Arrays.asList(
                Keys.EHR_FOLDER_DATA__EHR_FOLDER_DATA_EHR_ID_EHR_FOLDERS_IDX_FKEY,
                Keys.EHR_FOLDER_DATA__EHR_FOLDER_EHR_ID_FKEY);
    }

    private transient EhrFolderVersion _ehrFolderVersion;
    private transient org.ehrbase.migration.importer.v4.jooq.pg.tables.Ehr _ehr;

    /**
     * Get the implicit join path to the <code>ehr.ehr_folder_version</code>
     * table.
     */
    public EhrFolderVersion ehrFolderVersion() {
        if (_ehrFolderVersion == null)
            _ehrFolderVersion =
                    new EhrFolderVersion(this, Keys.EHR_FOLDER_DATA__EHR_FOLDER_DATA_EHR_ID_EHR_FOLDERS_IDX_FKEY);

        return _ehrFolderVersion;
    }

    /**
     * Get the implicit join path to the <code>ehr.ehr</code> table.
     */
    public org.ehrbase.migration.importer.v4.jooq.pg.tables.Ehr ehr() {
        if (_ehr == null)
            _ehr = new org.ehrbase.migration.importer.v4.jooq.pg.tables.Ehr(
                    this, Keys.EHR_FOLDER_DATA__EHR_FOLDER_EHR_ID_FKEY);

        return _ehr;
    }

    @Override
    public EhrFolderData as(String alias) {
        return new EhrFolderData(DSL.name(alias), this);
    }

    @Override
    public EhrFolderData as(Name alias) {
        return new EhrFolderData(alias, this);
    }

    @Override
    public EhrFolderData as(Table<?> alias) {
        return new EhrFolderData(alias.getQualifiedName(), this);
    }

    /**
     * Rename this table
     */
    @Override
    public EhrFolderData rename(String name) {
        return new EhrFolderData(DSL.name(name), null);
    }

    /**
     * Rename this table
     */
    @Override
    public EhrFolderData rename(Name name) {
        return new EhrFolderData(name, null);
    }

    /**
     * Rename this table
     */
    @Override
    public EhrFolderData rename(Table<?> name) {
        return new EhrFolderData(name.getQualifiedName(), null);
    }

    // -------------------------------------------------------------------------
    // Row15 type methods
    // -------------------------------------------------------------------------

    @Override
    public Row15<
                    UUID,
                    Integer,
                    UUID,
                    Integer,
                    Integer,
                    String,
                    String,
                    String,
                    String,
                    String,
                    String,
                    String,
                    String,
                    Integer,
                    JSONB>
            fieldsRow() {
        return (Row15) super.fieldsRow();
    }

    /**
     * Convenience mapping calling {@link SelectField#convertFrom(Function)}.
     */
    public <U> SelectField<U> mapping(
            Function15<
                            ? super UUID,
                            ? super Integer,
                            ? super UUID,
                            ? super Integer,
                            ? super Integer,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super Integer,
                            ? super JSONB,
                            ? extends U>
                    from) {
        return convertFrom(Records.mapping(from));
    }

    /**
     * Convenience mapping calling {@link SelectField#convertFrom(Class,
     * Function)}.
     */
    public <U> SelectField<U> mapping(
            Class<U> toType,
            Function15<
                            ? super UUID,
                            ? super Integer,
                            ? super UUID,
                            ? super Integer,
                            ? super Integer,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super String,
                            ? super Integer,
                            ? super JSONB,
                            ? extends U>
                    from) {
        return convertFrom(toType, Records.mapping(from));
    }
}
